package com.pingsky.apm.agent.api;

import com.pingsky.apm.agent.api.util.FileUtil;
import com.pingsky.apm.agent.api.util.JarUtil;

import java.io.File;

/**
 * agent目录信息
 *
 * @author zifeihan
 */
public class AgentDir {

    private File libDir;
    private File logDir;
    private File pluginDir;
    private File configFile;
    private File bootStrapJarFile;

    private AgentDir() {
        String jarLocation = JarUtil.getJarLocation(AgentDir.class.getName());
        this.bootStrapJarFile = new File(jarLocation);
        this.libDir = FileUtil.fileExist(this.bootStrapJarFile.getParent(), "lib");
        this.logDir = FileUtil.fileExist(this.bootStrapJarFile.getParent(), "log");
        this.pluginDir = FileUtil.fileExist(this.bootStrapJarFile.getParent(), "plugin");
        this.configFile = FileUtil.fileExist(this.bootStrapJarFile.getParent(), "pingsky.config");
    }

    private static AgentDir agentDir = null;

    public static AgentDir getInstance() {
        if (null == agentDir) {
            agentDir = new AgentDir();
        }
        return agentDir;
    }

    public File getLibDir() {
        return libDir;
    }

    public File getLogDir() {
        return logDir;
    }

    public File getPluginDir() {
        return pluginDir;
    }

    public File getConfigFile() {
        return configFile;
    }

    public File getBootStrapJarFile() {
        return bootStrapJarFile;
    }
}
